package packet;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import sql.ReadOldInfo;
import DataClass.OldInfo;
import TCP.Communication.CommunicationServer;
import TCP.Communication.LinkerClient;
import TCP.Communication.LinkerServer;
import TCP.Packet.sys.Packet_i;

public class SendOldInfo implements Packet_i, Serializable{

	public List<Integer> ids_oldlist= new ArrayList<Integer>();
	public List<String> names_oldlist= new ArrayList<String>();
	public List<String> tels_oldlist= new ArrayList<String>();
	
	public void addOldInfo(OldInfo elem) {
		ids_oldlist.add(elem.id);
		names_oldlist.add(elem.name);
		tels_oldlist.add(elem.tel);
	}
	
	public List<OldInfo> getOldlists() {
		List<OldInfo> oldlist= new ArrayList<OldInfo>(ids_oldlist.size());
		for(int i=0; i<ids_oldlist.size(); i++) {
			
			OldInfo elem_added= new OldInfo();
			
			elem_added.id= ids_oldlist.get(i);
			elem_added.name= names_oldlist.get(i);
			elem_added.tel= tels_oldlist.get(i);
			oldlist.add(elem_added);
		}
		return oldlist;
	}
	
	@Override
	public void runOnServer(LinkerServer ls) {
		CommunicationServer.cs.sendTo指定名稱(ls, this, new String[]{"angel"});
		
	}

	@Override
	public void runOnClient(LinkerClient lc) {
		ReadOldInfo a=new ReadOldInfo();
		a.ReadOld(getOldlists());
		
	}
	
	public SendOldInfo() {
	}

}
